<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    <title>商品分类</title>
</head>

<body>
<style>
    .fbutton .add {
        background: url("/framework/flexigrid/css/images/add.png") no-repeat scroll left center rgba(0, 0, 0, 0);
    }
     div.tDiv {
        background: url("/framework/flexigrid/css/images/bg.gif") repeat-x scroll center top #FAFAFA;
        border-color: #CCCCCC #CCCCCC -moz-use-text-color;
        padding:8px;
    }
    #img_add_1,.add,a{
        cursor: pointer;
    }

    .items{
        width:73%;
    }
    .tal{
        text-align: center;
    }
</style>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_content">

        <div class="items2" id = "cate_table" style="margin:0px auto;width:900px;border-top:0px;">
        	<!--{if $edit_permission}-->
                <div class="tDiv">
                    <div class="tDiv2">
                        <div class="fbutton">
                            <div>
                                <span class="add" style="padding-left: 20px;" onclick = 'category.add()'>添加</span>
                            </div>
                        </div>
                    </div>
                    <div style="clear:both"></div>
                </div>    
            <!--{/if}-->
            <table id="goods_table" class="s" style="width: 100%;margin: 0 auto 8px;">
                <thead>
                <tr>
                    <th style="padding: 0;">
                        分类
                    </th>
                    <th style="width: 20%;padding: 0;">分类类型</th>
                    <th style="width: 15%;padding: 0;">使用状态</th>
                    <!--{if $edit_permission}-->
                    	<th style="width: 15%;padding: 0;">操作</th>
                    <!--{/if}-->
                </tr>
                </thead>

                <tbody>
                <!--{foreach from = $result_data item = value}-->

                <tr id = 'cate<!--{$value.bigCategoryID}-->' >
                    <td style="text-align: left;">
                        <div id="tdone_<!--{$value.bigCategoryID}-->" style="float:left">
                            <!--{if $value.ismid == 1}-->
                            <img id="img_add_1" onclick="category.add_cate(<!--{$value.bigCategoryID}-->,'')" src="/quanliadmin/docroot/images/bag_open.gif">&nbsp;
                            <!--{/if}-->
                        </div>
                        <div style = "float:left">
                            <!--{$value.bigCategoryID}-->
                            <span style="font-size:13px;font-weight:bold;">【<!--{$value.description}-->】</span>
                        </div>

                    </td>
                    <td class="tal">
                        大分类
                    </td>
                    <td>
                        <div id = "useflg_<!--{$value.bigCategoryID}-->" style="text-align: center">
                        	<!--{if $edit_permission}-->
                        		<!--{if $value.useFlg == 1}-->
                                	<a onclick = "category.doAction(<!--{$value.bigCategoryID}-->,0)">启用</a>
                                <!--{/if}-->
                                <!--{if $value.useFlg == 0}-->
                                	<a onclick = "category.doAction(<!--{$value.bigCategoryID}-->,1)">禁用</a>
                                <!--{/if}-->
                        	<!--{else}-->
                        		<!--{if $value.useFlg == 1}-->
                                	启用
                                <!--{/if}-->
                                <!--{if $value.useFlg == 0}-->
                                	禁用
                                <!--{/if}-->
                        	<!--{/if}-->
                           
                        </div>
                    </td>
					<!--{if $edit_permission}-->
                        <td style="text-align: center;">
                            <a onclick = "category.cateedit(<!--{$value.bigCategoryID}-->)">编辑</a>
                            <!--<a onclick = "category.catedelete(<!--{$value.bigCategoryID}-->)">删除</a>-->
                        </td>
					<!--{/if}-->
                </tr>

                <!--{/foreach}-->
                </tbody>
            </table>
        </div>

    </div>

</div>

<script type="text/javascript">

    var category = {
        //显示分类
        add_cate: function(cate_id,mid){
            var cate = '#cate' //分类ID前缀
            if(mid != ''){
                cate = '#mcate'
            }
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/goodsCate.ajax?operFlg=1&mid="+mid+"&xjx=none",
                dataType: "JSON",
                data: {'cate_id':cate_id},
                success: function( result_obj ) {
                    $('#tdone_'+cate_id).html('<img id="img_add_1" onclick="category.remove_cate('+cate_id+',\''+mid+'\')" src="/quanliadmin/docroot/images/bag_close.gif">&nbsp;');
                    $(result_obj.tr).insertAfter(cate+cate_id)
                }
            })
        },
        //添加分类
        add: function() {
            E.open("/quanliadmin/app/goods/goodsCate.pscript?operFlg=2");
        },
        //隐藏分类
        remove_cate: function(cate_id,mid){
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/goodsCate.ajax?operFlg=2&mid="+mid+"&xjx=none",
                dataType: "JSON",
                data: {'cate_id':cate_id},
                success: function( result_obj ) {
                    $(result_obj).each(function(i,n){
                        $('#tdone_'+cate_id).html('<img id="img_add_1" onclick="category.add_cate('+cate_id+',\''+mid+'\')" src="/quanliadmin/docroot/images/bag_open.gif">&nbsp;');
                        $('#mcate'+n).remove();
                        $('#scate'+n).remove();
                    })
                }
            })
        },
        
        //编辑分类
        cateedit: function(categoryID){
            E.open('/quanliadmin/app/goods/goodsCate.pscript?operFlg=3&categoryID='+categoryID);
        },
        edit_show: function(){

        },
        cStr : '' ,
        uFlg : '' ,
        delete_str: '',
        //删除分类
        catedelete: function(delete_str){
            this.delete_str = delete_str;
            E.confirm("您确认要删除选中的分类吗？", "category.deleteConfirm");
        },
        deleteConfirm: function(){
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/goodsCate.ajax?operFlg=4&delete_str=" + category.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2);
                        $(result_obj.cate_arr).each(function(i,n){
                            $('#cate'+n).remove();
                            $('#mcate'+n).remove();
                            $('#scate'+n).remove();
                        })
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        //使用禁用分类
        doAction: function( categoryStr , useFlg) {
            this.useFlg_str = categoryStr + "_" + useFlg ;
            this.cStr = categoryStr;
            this.uFlg = useFlg;
            if( useFlg == 0 )
                E.confirm("您确认要禁用此商品分类吗？", "category.actionConfirm");
            else
                category.actionConfirm() ;
        },

        actionConfirm : function () {
        	E.loadding.open('请稍候...');
        	
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/goodsCate.ajax?operFlg=3&useFlg_str=" + category.useFlg_str,
                dataType: "JSON",
                success: function( result_obj ) {
                	E.loadding.close();
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2);
                        if(category.uFlg == 0)
                        $('#useflg_'+category.cStr).html('<a onclick = "category.doAction(\''+category.cStr+'\',1)">禁用</a>');
                        else
                        $('#useflg_'+category.cStr).html('<a onclick = "category.doAction(\''+category.cStr+'\',0)">启用</a>');
                        this.cStr = '';
                        this.uFlg = '';

                    } else {
                    	E.loadding.close();
                        E.alert(result_obj.message);
                    }
                }
            })
        }
    }

</script>

</body>

</html>
